package com.example.demojenkins.service.impl;


import com.example.demojenkins.entity.TblOrderInfo;
import com.example.demojenkins.mapper.TblOrderInfoDao;
import com.example.demojenkins.service.TblOrderInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TblOrderInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-09-15 12:50:27
 */
@Service("tblOrderInfoService")
public class TblOrderInfoServiceImpl implements TblOrderInfoService {
    @Resource
    private TblOrderInfoDao tblOrderInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TblOrderInfo queryById(Integer id) {
        return this.tblOrderInfoDao.queryById(id);
    }

    @Override
    public List<TblOrderInfo> queryAll() {

        return this.tblOrderInfoDao.queryAll();
    }

    @Override
    public Long count(TblOrderInfo tblOrderInfo) {
        return this.tblOrderInfoDao.count(tblOrderInfo);
    }

    /**
     * 分页查询
     *
     * @param tblOrderInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TblOrderInfo> queryByPage(TblOrderInfo tblOrderInfo, PageRequest pageRequest) {
        long total = this.tblOrderInfoDao.count(tblOrderInfo);
        return new PageImpl<>(this.tblOrderInfoDao.queryAllByLimit(tblOrderInfo, pageRequest), pageRequest, total);
    }

    @Override
    public List<TblOrderInfo> queryByPage2(Integer page, Integer size, String orderName) {
        return tblOrderInfoDao.queryByPage2(page,size, orderName);
    }


    /**
     * 新增数据
     *
     * @param tblOrderInfo 实例对象
     * @return 实例对象
     */
    @Override
    public TblOrderInfo insert(TblOrderInfo tblOrderInfo) {
        tblOrderInfoDao.insert(tblOrderInfo);
        return tblOrderInfo;
    }

    /**
     * 修改数据
     *
     * @param tblOrderInfo 实例对象
     * @return 实例对象
     */
    @Override
    public TblOrderInfo update(TblOrderInfo tblOrderInfo) {
        this.tblOrderInfoDao.update(tblOrderInfo);
        return this.queryById(tblOrderInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tblOrderInfoDao.deleteById(id) > 0;
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        this.tblOrderInfoDao.deleteByIds(ids);
    }
}
